package com.xhgj.thread;

/**
 * @author 周宇
 * @create 2020-06-27 23:42
 * 线程优先级
 */
public class PriorityThread {
    public static void main(String[] args) {
        //默认优先级
        System.out.println(Thread.currentThread().getName() + "-->" + Thread.currentThread().getPriority());
        MyPriority p = new MyPriority();
        Thread t1 = new Thread(p, "t1");
        Thread t2 = new Thread(p, "t2");
        Thread t3 = new Thread(p, "t3");
        Thread t4 = new Thread(p, "t4");
        Thread t5 = new Thread(p, "t5");
        Thread t6 = new Thread(p, "t6");
        //先设置优先级再启动
        t1.start();
        t2.setPriority(1);
        t2.start();
        t3.setPriority(4);
        t3.start();
        t4.setPriority(Thread.MAX_PRIORITY);//10
        t4.start();
        t5.setPriority(8);
        t5.start();
        t6.setPriority(11);
        t6.start();
    }
}

class MyPriority implements Runnable {
    @Override
    public void run() {
        //打印线程名--》优先级
        System.out.println(Thread.currentThread().getName() + "-->" + Thread.currentThread().getPriority());
    }
}
